package cn.waterr.luban.demo.cart.dubbo;

import cn.water.luban.demo.cart.api.CartApi;
import cn.waterr.luban.demo.cart.main.rpc.CartApiImpl;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;

public class ProviderServer {
    public static void main(String[] args) {
        DubboBootstrap server = DubboBootstrap.getInstance();//dubbo应用
        server.application("cart-provider");
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(-1);//从20880开始找一个可用的
        server.protocol(protocolConfig);
        //连接注册到nacos
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("nacos");
        registryConfig.setAddress("localhost:8848");
        server.registry(registryConfig);
        //注册功能等信息
        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setInterface(CartApi.class);
        serviceConfig.setRef(new CartApiImpl());
        server.service(serviceConfig);
        //provider可以启动了
        server.start().await();
    }
}
